<?php

// Route::get('/', 'PagesController@root')->name('root');
Route::redirect('/', '/products')->name('root');

// 商品
Route::get('products', 'ProductsController@index')->name('products.index');

// 开启邮箱验证
Auth::routes(['verify' => true]);

// auth 登录认证，verified邮箱验证
Route::group(['middleware' => ['auth', 'verified']], function () {

    // 地址
    Route::get('user_addresses', 'UserAddressesController@index')->name('user_addresses.index');
    Route::get('user_addresses/create', 'UserAddressesController@create')->name('user_addresses.create');
    Route::post('user_addresses', 'UserAddressesController@store')->name('user_addresses.store');
    Route::get('user_addresses/{user_address}', 'UserAddressesController@edit')->name('user_addresses.edit');
    Route::put('user_addresses/{user_address}', 'UserAddressesController@update')->name('user_addresses.update');
    Route::delete('user_addresses/{user_address}', 'UserAddressesController@destroy')->name('user_addresses.destroy');

    // 收藏/欢喜
    Route::post('products/{product}/favorite', 'ProductsController@favor')->name('products.favor');
    Route::delete('products/{product}/favorite', 'ProductsController@disfavor')->name('products.disfavor');
    Route::get('products/favorites', 'ProductsController@favorites')->name('products.favorites');

    // 购物车
    Route::post('cart', 'CartController@add')->name('cart.add');
    Route::get('cart', 'CartController@index')->name(('cart.index'));
    Route::delete('cart/{sku}', 'CartController@remove')->name('cart.remove');

    // 订单
    Route::get('orders','OrdersController@index')->name('orders.index');
    Route::post('orders', 'OrdersController@store')->name('orders.store');
    Route::get('orders/{order}','OrdersController@show')->name('orders.show');
    // 确认收货
    Route::post('orders/{order}/recieved','OrdersController@received')->name('orders.received');
    // 评价
    Route::get('orders/{order}/review','OrdersController@review')->name('orders.review.show');
    Route::post('orders/{order}/review','OrdersController@sendReview')->name('orders.review.store');
    // 退款
    Route::post('orders/{order}/apply_refund','OrdersController@applyRefund')->name('orders.apply_refund');

    // 支付宝支付
    Route::get('payment/{order}/alipay','PaymentController@payByAlipay')->name('payment.alipay');
    Route::get('payment/alipay/return','PaymentController@alipayReturn')->name('payment.alipay.return');
    // 微信支付
    Route::get('payment/{order}/wechat','PaymentController@payByWechat')->name('payment.wechat');

    // 优惠券查询
    Route::get('coupon_codes/{code}','CouponCodesController@show')->name('coupon_codes.show');
});

// 注册路由的顺序，从前往后，前面路由找到了，后面不再被匹配响应
Route::get('products/{product}', 'ProductsController@show')->name('products.show');

// 支付宝服务端回调
Route::post('payment/alipay/notify', 'PaymentController@alipayNotify')->name('payment.alipay.notify');
// 微信支付服务端回调,退款回调
Route::post('payment/wechat/notify', 'PaymentController@wechatNotify')->name('payment.wechat.notify');
Route::post('payment/wechat/refund_notify', 'PaymentController@wechatRefundNotify')->name('payment.wechat.refund_notify');
